package com.sf.hackathons.app.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sf.hackathons.app.R;
import com.sf.hackathons.app.bean.test.TestBean;
import com.sf.hackathons.lib.commui.base.BaseRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by chengzi on 2017/12/14.
 */

public class DemoAdapter extends RecyclerView.Adapter<DemoAdapter.ViewHolder> {
    List<TestBean> mPushList = new ArrayList<>();
    private Context mContext;
    TestBean msgBean;
    private BaseRecyclerViewAdapter.OnItemClickListener onItemClickListener;

    public DemoAdapter(Context context, List<TestBean> mPushList, BaseRecyclerViewAdapter.OnItemClickListener onItemClickListener) {
        this.mContext = context;
        this.mPushList = mPushList;
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public DemoAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_test_listview, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        msgBean = mPushList.get(position);
        holder.mTitle.setText(msgBean.title);
        if (onItemClickListener != null) {
            holder.view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(holder.view, position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return this.mPushList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        View view;

        @BindView(R.id.mTxtTitle)
        TextView mTitle;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.view = itemView;
        }
    }

}
